/*
    主题发布订阅测试：主题订阅客户端
*/

#include "../../client/rpc_client.hpp"
#include "../../common/log.hpp"

// 订阅回调函数
void subscribeCallback(const std::string &topicName, const std::string &msg)
{
    LOG_INFO("%s topic publish message: %s\n", topicName.c_str(), msg.c_str());
}

int main()
{
    SetDefaultLogLevel(Level::INFO);
    EnableSaveFile();
    
    // 1、定义主题客户端
    ns_jsonrpc::ns_client::TopicClient::TopicClientPtr clt = std::make_shared<ns_jsonrpc::ns_client::TopicClient>("127.0.0.1", 8080);

    // 2、主题创建
    clt->topicCreate("music");
    clt->topicCreate("movie");

    // 3、主题订阅
    clt->topicSubscribe("music", subscribeCallback);
    clt->topicSubscribe("movie", subscribeCallback);
    std::this_thread::sleep_for(std::chrono::seconds(50));
    return 0;
}
